home *** CD-ROM | disk | FTP | other *** search
/ 3D Images / 3D Images.iso / programs / amiga / rayshade / libshade / objdef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-12  |  2.5 KB  |  121 lines

  1. /*
  2.  * objdef.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * objdef.c,v 4.1 1994/08/09 08:04:35 explorer Exp
  17.  *
  18.  * objdef.c,v
  19.  * Revision 4.1  1994/08/09  08:04:35  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:17  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:46:38  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29.  
  30. #include "rayshade.h"
  31. #include "options.h"
  32. #include "stats.h"
  33.  
  34. static Geom *Objects = NULL;        /* named objects */
  35. Geom *World;                /* top-level object */
  36.  
  37.  
  38. /*
  39.  * Return pointer to named object, NULL if no such object has been defined.
  40.  */
  41. Geom *
  42. GeomGetNamed(name)
  43. char *name;
  44. {
  45.     Geom *otmp;
  46.     for (otmp = Objects; otmp; otmp = otmp->next)
  47.         if (strcmp(name, otmp->name) == 0)
  48.             return otmp;
  49.     return (Geom *)NULL;
  50. }
  51.  
  52. /*
  53.  * Add object to list of defined objects.  At this point, the object has
  54.  * been converted to the correct type, and obj->next is either NULL or
  55.  * garbage.
  56.  */
  57. void
  58. GeomAddToDefined(obj)
  59. Geom *obj;
  60. {
  61.     obj->next = Objects;
  62.     Objects = obj;
  63.     if (Options.verbose)
  64.         AggregatePrintInfo(obj, Stats.fstats);
  65.     else
  66.         AggregatePrintInfo(obj, (FILE *)NULL);
  67. }
  68.  
  69. /*
  70.  * Return a copy of the named object.
  71.  */
  72. Geom *
  73. GeomCopyNamed(name)
  74. char *name;
  75. {
  76.     Geom *child;
  77.  
  78.     child = GeomGetNamed(name);
  79.     if (child == (Geom *)NULL)
  80.         RLerror(RL_PANIC, "There is no object named \"%s\".", name);
  81.     child = GeomCopy(child);
  82.     return child;
  83. }
  84.  
  85. void
  86. WorldSetup()
  87. {
  88.     extern GeomList *Defstack;
  89.  
  90.     /*
  91.      * Define World object, if not done previously.
  92.      */
  93.     if (World == (Geom *)NULL) {
  94.         World = Defstack->obj;    /* World is topmost object on stack */
  95.         if (Defstack->next)
  96.             RLerror(RL_ABORT, "Geom def stack is screwey.\n");
  97.         World->prims = AggregateConvert(World, World->next);
  98.     }
  99.  
  100.     GeomComputeBounds(World);
  101.  
  102.     /*
  103.      * Complain if there are no primitives to be rendered.
  104.      */
  105.     if (World->prims == 0) {
  106.         RLerror(RL_PANIC, "Nothing to be rendered.\n");
  107.     }
  108. }
  109.  
  110. /*
  111.  * Main ray-spwaning routine required by libray
  112.  */
  113. int
  114. TraceRay(ray, hitlist, mindist, maxdist)
  115. Ray *ray;
  116. HitList *hitlist;
  117. Float mindist, *maxdist;
  118. {
  119.     return intersect(World, ray, hitlist, mindist, maxdist);
  120. }
  121.